//
//  DKAuthFailView.m
//  DanKU
//
//  Created by 吴斌 on 2023/11/5.
//

#import "DKAuthFailView.h"

@interface DKAuthFailView()
@property (nonatomic, weak)zhPopupController * dk_AuthFailViewPop;
@property (nonatomic,strong)DKAuthFailView *dk_AuthFailView;
@property (nonatomic, copy)void(^SureAuthFailAlertBlock)(void);
@end
@implementation DKAuthFailView
-(instancetype)init{
    if(self == [super init]){
        self.backgroundColor = UIColor.whiteColor;
        self.layer.cornerRadius = 50;
        self.clipsToBounds = YES;
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    UIImageView * dk_AuthFaceImgView = [[UIImageView alloc] init];
    dk_AuthFaceImgView.image = DK_GetImage(@"dk_AuthFailIcon");
    dk_AuthFaceImgView.userInteractionEnabled = YES;
    [self addSubview:dk_AuthFaceImgView];
    [dk_AuthFaceImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(@(DK_IsWidthScale(29)));
        make.width.equalTo(@(DK_IsWidthScale(30)));
        make.height.equalTo(@(DK_IsWidthScale(30)));
    }];
    
    UILabel *dk_AuthStartHeadLab = [[UILabel alloc] init];
    dk_AuthStartHeadLab.textColor = DK_Hex(@"#4566FF");
    dk_AuthStartHeadLab.font = DK_FONT_Medium(17);
    dk_AuthStartHeadLab.text = @"Facial recognition verification failed. You can take a photo again to verify";
    dk_AuthStartHeadLab.numberOfLines = 0;
    dk_AuthStartHeadLab.textAlignment = NSTextAlignmentCenter;
    [self addSubview:dk_AuthStartHeadLab];
    [dk_AuthStartHeadLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(dk_AuthFaceImgView.mas_bottom).offset(DK_IsWidthScale(10));
        make.left.equalTo(@(DK_IsWidthScale(36)));
        make.right.equalTo(@(-DK_IsWidthScale(36)));
        make.centerX.equalTo(self);
    }];
    UILabel *dk_AuthStartContentLab = [[UILabel alloc] init];
    dk_AuthStartContentLab.textColor = DK_Hex(@"#333333");
    dk_AuthStartContentLab.font = DK_FONT_Regular(14);
    dk_AuthStartContentLab.numberOfLines = 0;
    dk_AuthStartContentLab.text = @"*Take a clear frontal photo of your face.\n*Take the photo in a well-lit environment.\n*Don't cover your face.\n*Hold your phone vertically and firmly.";
    [self addSubview:dk_AuthStartContentLab];
    [dk_AuthStartContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(dk_AuthStartHeadLab.mas_bottom).offset(DK_IsWidthScale(20));
        make.left.equalTo(@(DK_IsWidthScale(10)));
        make.right.equalTo(@(-DK_IsWidthScale(10)));
    }];
    UIButton * dk_AuthStartBtn = [[UIButton alloc] init];
    [dk_AuthStartBtn setTitle:@"Ok" forState:UIControlStateNormal];
    [dk_AuthStartBtn setTitleColor:DK_Hex(@"#FFFFFF") forState:UIControlStateNormal];
    dk_AuthStartBtn.titleLabel.font = DK_FONT_Semibold(16);
    [dk_AuthStartBtn setBackgroundColor:DK_Hex(@"#4566FF")];
    dk_AuthStartBtn.layer.cornerRadius = DK_IsWidthScale(25);
    dk_AuthStartBtn.clipsToBounds = YES;
    [dk_AuthStartBtn addTarget:self action:@selector(startAuth) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:dk_AuthStartBtn];
    [dk_AuthStartBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.height.equalTo(@(DK_IsWidthScale(50)));
        make.bottom.equalTo(@(-DK_IsWidthScale(40)));
    }];
}
- (void)startAuth{
    [_dk_AuthFailViewPop dismiss];
    if(self.SureAuthFailAlertBlock){
        self.SureAuthFailAlertBlock();
    }
}
+ (void)dk_ShowAuthFailAlertView:(void(^)(void))complete{
    DKAuthFailView * dk_AuthFailView = [[DKAuthFailView alloc] init];
    zhPopupController * sureAuthStartCtrl = [[zhPopupController alloc] initWithView:dk_AuthFailView size:CGSizeMake(DK_SCREEN_W - DK_IsWidthScale(60), DK_IsWidthScale(371))];
    dk_AuthFailView.SureAuthFailAlertBlock = complete;
    sureAuthStartCtrl.presentationStyle = zhPopupSlideStyleTransform;
    sureAuthStartCtrl.layoutType = zhPopupLayoutTypeCenter;
    sureAuthStartCtrl.presentationTransformScale = 0.56;
    sureAuthStartCtrl.dismissonTransformScale = 0.56;
    sureAuthStartCtrl.dismissOnMaskTouched = NO;
    dk_AuthFailView.dk_AuthFailViewPop = sureAuthStartCtrl;
    [sureAuthStartCtrl showInView:((AppDelegate*)([UIApplication sharedApplication].delegate)).window completion:^{
    }];
}
@end
